home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11279 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: problem w/ realloc
  5. Date: 22 Mar 1996 22:46:29 GMT
  6. Organization: OpenVision
  7. Message-ID: <4ivak5$95t@spanky.pls.ov.com>
  8. References: <4iqef0$dqq@montana.avicom.net>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article dqq@montana.avicom.net, zoot@montana.avicom.net (John Greenup) writes:
  13. >I've been porting a piece of code from AIX 3.2.5 to linux 1.2.8
  14. >(gcc 2.7.0) recently, and finaly chased down the last :-) bug.  The code 
  15. >assumes that if you have a memory block, and you realloc it smaller, it 
  16. >doesn't move the block of memory, it just makes the "usable size" of it 
  17. >smaller. (in fact, my textbook ("advanced programming in the unix 
  18. >environment" stevens) supports this usage) unfortunately, xxgdb has 
  19. >revealed that the realloc is moving my pointer!  am I mistaken about the 
  20. >standards, or is this a special case I'm not aware of?
  21. >any help appreciated-
  22. >john greenup
  23. >Zoot Enterprises
  24. >zoot@www.avicom.net
  25. >
  26.  
  27.  
  28. To what standard are you referring?  All that realloc promises to do is to 
  29. return a pointer to a memory area of the specified size and to preserve
  30. existing data (if any).  There is nothing in the function description that
  31. says anything about where this pointer will point to, nor is there any
  32. guarantee that it will not change from the pointer given to the function.
  33. You cannot and must not make any assumptions about the values returned
  34. from allocation routines except for NULL.
  35.  
  36.         Fletcher.Glenn@ov.com
  37.  
  38.  
  39.